<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org/">
<head>
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
    <script th:src="@{/static/jquery-2.1.4.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/layui/layui.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/mylayer.js}" type="text/javascript" charset="utf-8"></script>
    <script th:src="@{/static/kindeditor/kindeditor.js}" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<!--搜索form表单-->
<!--<form class="layui-form layui-row layui-col-space16">
    订单号：
    <div class="layui-inline layui-input-wrap">
        <input type="text" name="orderNo" value="" class="layui-input" lay-affix="clear">
    </div>
    支付类型：
    <div class="layui-inline layui-input-wrap">
        <input type="text" name="paymentType" value="" class="layui-input" lay-affix="clear">
    </div>


    <div class="layui-inline">
        <button class="layui-btn" lay-submit lay-filter="submitSearch">Search</button>
        <button type="reset" class="layui-btn layui-btn-primary">Clear</button>
    </div>
</form>-->

<table class="layui-hide" id="test" lay-filter="test"></table>
<!--头部工具条-->
<!--<script id="toolbarDemo" type="text/html">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="deleteAll">批量删除</button>
    </div>
</script>-->
<!--右侧工具条-->
<!--<script type="text/html" id="barDemo">
    <div class="layui-clear-space">
        <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="delete">删除</a>
        <a class="layui-btn layui-btn-xs" lay-event="update">编辑</a>
        <a class="layui-btn layui-btn-xs" lay-event="detail">详情</a>
    </div>
</script>-->

<script type="text/html" id="imageTemplet">
    <img src="/pic/{{d.productImage}}"></img>
</script>

<!--table中展示status的templet-->
<script type="text/html" id="statusTemplet">

</script>

<script>
    layui.use(['table', 'form', 'upload','laydate'], function () {
        var form = layui.form;
        var table = layui.table;
        var laydate = layui.laydate;

        //拿到order_list.jsp传递过来的参数--编辑回显数据
        var queryString = window.location.search;
        var urlParams = new URLSearchParams(queryString);
        var orderNo = urlParams.get("orderNo");


        // 创建渲染实例
        table.render({
            elem: '#test',
            id: 'tableId',
            url: '/orderItem/list?orderNo=' + orderNo,
            toolbar: '#toolbarDemo',
            cols: [
                [
                    /*{type: 'checkbox', fixed: 'left'},*/
                    /*{field: 'id', title: 'ID', sort: true, width: 100},
                    {field: 'userId', title: '用户id'},*/
                    {field: 'orderNo', title: '订单号'},
                    {field: 'productId', title: '商品id'},
                    {field: 'productName', title: '商品名称'},
                    {field: 'productImage', title: '商品照片',templet:'#imageTemplet'},
                    {field: 'currentUnitPrice', title: '生成订单时的商品单价'},
                    {field: 'quantity', title: '商品数量'},
                    {field: 'totalPrice', title: '商品总价'},
                    //{field: 'status', title: '状态',templet: '#statusTemplet'},
                    {field: 'status', title: '状态'},
                    {field: 'createTime', title: '创建时间'},
                    {field: 'updateTime', title: '更新时间'}
                    /*{fixed: 'right', title: '操作', width: 134, minWidth: 125, toolbar: '#barDemo'}*/
                ]
            ],
            page: true
        });

        // 搜索提交
        form.on('submit(submitSearch)', function (data) {
            var field = data.field; // 获得表单字段
            // 执行搜索重载
            table.reload('tableId', {
                page: {
                    curr: 1 // 重新从第 1 页开始
                },
                where: field // 搜索的字段
            });
            return false; // 阻止默认 form 跳转
        });

        // 头部工具栏事件
        /*table.on('toolbar(test)', function (obj) {
            var id = obj.config.id;
            var checkStatus = table.checkStatus(id);
            var othis = lay(this);
            switch (obj.event) {
                case 'add':
                    var index = layer.open({
                        type: 2,
                        title: '添加数据',
                        area: ['90%', '90%'], // 宽高
                        content: '/page/order/add'
                    });
                    break;
                case 'deleteAll':
                    var data = checkStatus.data;
                    //[{"id":2,"name":"Java1812","address":"ddf","time":"232"},{"id":3,"name":"Java1903","address":"34","time":"323"}]
                    var ids = new Array();
                    $(data).each(function () {
                        ids.push(this.id);
                    })
                    //[2,4]
                    layer.confirm(
                        '您确认要删除么?',
                        {icon: 3},
                        function (index) {
                            $.post(
                                '/order/deleteAll',
                                {'ids': ids},
                                function (result) {
                                    console.log(result);
                                    if (result.code == 0) {
                                        mylayer.okMsg(result.msg);
                                        //删除成功之后刷新表格，展示最新数据
                                        table.reload('tableId');
                                    } else {
                                        mylayer.errorMsg(result.msg);
                                    }
                                },
                                'json'
                            );
                        }
                    );
                    break;
                case 'LAYTABLE_TIPS':
                    layer.alert('自定义工具栏图标按钮');
                    break;
            }
            ;
        });*/

        // 触发单元格工具事件
        /*table.on('tool(test)', function (obj) { // 双击 toolDouble
            var data = obj.data; // 获得当前行数据
            console.log(obj);
            //{"id": 1,"name": "Java1807","address": "dfdf","time": "3434"}
            console.log(obj.data);
            if (obj.event === 'delete') {
                layer.confirm(
                    '您确认要删除么?',
                    {icon: 3},
                    function (index) {
                        $.post(
                            '/order/deleteById',
                            {'id': data.id},
                            function (result) {
                                console.log(result);
                                if (result.code == 0) {
                                    mylayer.okMsg(result.msg);
                                    //删除成功之后刷新表格，展示最新数据
                                    table.reload('tableId');
                                } else {
                                    mylayer.errorMsg(result.msg);
                                }
                            },
                            'json'
                        );
                    }
                );
            } else if (obj.event === 'update') {
                var index = layer.open({
                    type: 2,
                    title: '编辑数据',
                    area: ['90%', '90%'], // 宽高
                    content: '/page/order/update?id='+data.id,
                });
            } else if (obj.event === 'detail') {
                layer.open({
                    type: 2,
                    title: data.name,
                    area: ['90%', '90%'], // 宽高
                    content: '/page/order/detail?orderNo='+data.orderNo,
                })
            }
        });*/

    });
</script>
</body>
</html>